package com.itheima.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.Student;
import com.itheima.service.StudentService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("studentServlet")
public class StudentController {
    @Reference
    private StudentService studentService;

    @RequestMapping("addStu")
    public void add(@RequestBody Student student) {
        studentService.save(student);
    }

    @RequestMapping("deleteStu/{number}")
    public void delete(@PathVariable String number) {
        studentService.delete(number);
    }

    @RequestMapping("updateStu")
    public void update(@RequestBody Student student) {
        studentService.update(student);
    }

    @RequestMapping("selectByPage")
    public PageInfo<Student> find(@RequestParam(value = "currentPage", required = false, defaultValue = "1") Integer currentPage,
                                  @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize) {
        PageInfo<Student> info = studentService.findAll(currentPage, pageSize);
        return info;
    }
}
